package andli.com.bmobtest;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import andli.com.bmobtest.bean.UserInfo;
import cn.bmob.v3.Bmob;
import cn.bmob.v3.listener.SaveListener;

/**
 * author andli
 * create at 16/9/27 下午10:55
 * Bomb的简单使用
 **/


public class MainActivity extends Activity {

    EditText carnum_txt;
    EditText phonenum_txt;

    Button commitButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //初始化Bmob
        Bmob.initialize(this, "9831a5f20e7c994d59517e9d454e13c9");

        carnum_txt      = (EditText)findViewById(R.id.carno);
        phonenum_txt    = (EditText)findViewById(R.id.phonenum);
        commitButton    = (Button)findViewById(R.id.commit);

        commitButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                //初始化实体类
                UserInfo info = new UserInfo();
                info.setCarnum(carnum_txt.getText().toString().trim());
                info.setPhonenum(phonenum_txt.getText().toString().trim());

                //提交数据
                if (carnum_txt.equals("") || phonenum_txt.equals("")){
                    Toast.makeText(MainActivity.this,"数据不能为空!",Toast.LENGTH_SHORT).show();
                    return;
                }
                info.save(MainActivity.this, new SaveListener() {
                    @Override
                    public void onSuccess() {
                        Toast.makeText(MainActivity.this,"插入成功!",Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onFailure(int i, String s) {
                        Toast.makeText(MainActivity.this,"插入失败!",Toast.LENGTH_SHORT).show();
                    }
                });

            }
        });




    }
}
